/*
 * BanBu_MySpaceViewController
 * @description 本文件提供我的空间界面的ViewController
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供我的空间界面的ViewController
 */

#import "BanBu_MySpaceViewController.h"
#import "BanBu_SettingViewController.h"
#import "BanBu_PersonDataViewController.h"
#import "BanBu_ProfileDataController.h"
#import "BanBu_DynamicController.h"
#import "UIBadgeView.h"
#import "AppCommunicationManager.h"
#import "AppDataManager.h"
#import "BanBu_ImageView.h"
#import "LeveyTabBarController.h"
#import "BanBu_ThemeManager.h"
#import "BanBu_PersonDataViewController.h"
#import "BanBu_BroadcastTVC.h"
#import "BanBu_EmoStoreViewController.h"
#import "BanBu_MyAccountViewController.h"
#import "BanBu_ThemeManager.h"
#import "BanBu_ImageView.h"
#import "UIButton+WebCache.h"
#import "RoundRectImage.h"
#import "BanBu_PersonAlbumDetailController.h"
#import "BanBu_HelpViewController.h"
@interface BanBu_MySpaceViewController ()
{
    BOOL  _isReceive;
}

@end

@implementation BanBu_MySpaceViewController


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super dealloc];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)viewWillDisappear:(BOOL)animated
{
//    if([[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"] valueForKey:@"boolKey"])
//    {
//        
//        NSMutableDictionary *settingsDic = [NSMutableDictionary dictionaryWithDictionary:[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"]];
//        
//        NSMutableArray  *boolArr=[NSMutableArray arrayWithArray:[[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"settings"] valueForKey:@"boolKey"]];
//        
//        [boolArr replaceObjectAtIndex:1 withObject:[NSNumber numberWithBool:_isReceive]];
//        
//        [settingsDic setValue:boolArr forKey:@"boolKey"];
//        
//        
//        NSMutableDictionary *settingsUpdata = [NSMutableDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
//        [settingsUpdata setValue:settingsDic forKey:@"settings"];
//        [UserDefaults setValue:settingsUpdata forKey:MyAppDataManager.useruid];
//    }
    
    [super viewWillDisappear:animated];
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [UIView setAnimationsEnabled:YES];
    [super viewWillAppear:animated];
    [self.leveyTabBarController hidesTabBar:NO  animated:YES];
    NSDictionary *profile = [NSDictionary dictionaryWithDictionary:[UserDefaults valueForKey:MyAppDataManager.useruid]];
    NSLog(@"%@",profile);
    [iconButton  setImageWithURL:[NSURL URLWithString:[profile valueForKey:@"uface"]] placeholderImage:[UIImage imageNamed:@"default.png"] andType:1];
    iconButton.layer.cornerRadius = 35;
    iconButton.layer.masksToBounds = YES;
//    iconButton.layer.borderColor = [[UIColor colorWithWhite:0.951 alpha:1.000] CGColor];
//    iconButton.layer.borderWidth = 0;
    
    
    
    pnameLabel.text = [profile valueForKey:@"pname"];
    if([profile valueForKey:@"userid"])
    {
        kooNumber.text = [@"ID : " stringByAppendingString:[profile valueForKey:@"userid"]];
    }
}
-(void)changeTheme
{
    scrollView.backgroundColor = [UIColor colorWithPatternImage:[ThemeManager getThemeImage:@"table_backimage.jpg"]];
}
- (void)viewDidLoad
{

    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheme) name:kThemeDidChangeNotification object:nil];
    
//    BanBu_ImageView *img = [[BanBu_ImageView alloc] initWithBackGroundImageType:UIImageViewCreatTypeTable];
//    [self.view addSubview:img];
    scrollView.backgroundColor = [UIColor colorWithPatternImage:[ThemeManager getThemeImage:@"table_backimage.jpg"]];

//    [scrollView insertSubview:img atIndex:0];
    myProfile.text = NSLocalizedString(@"myinfoLabel", nil);
    myDynamic.text = NSLocalizedString(@"myDynamic", nil);
    myAlbum.text = NSLocalizedString(@"myalbumTitle", nil);
    myAccount.text = NSLocalizedString(@"myAccount", nil);
    EmoShop.text = NSLocalizedString(@"emoStore", nil);
    mySetting.text = NSLocalizedString(@"systemLabel", nil);
    aboutKoochat.text = NSLocalizedString(@"helpTitle", nil);
    
    
//    UIButton *aButton = (UIButton *)[self.view viewWithTag:1112];
    NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey];
    
    if(![MyAppDataManager.newVersionNumber isEqual:version])
    {
        UIBadgeView *badgeView = [[[UIBadgeView alloc] initWithFrame:CGRectMake(30, -5, 50, 20)] autorelease];
        badgeView.backgroundColor = [UIColor clearColor];
        badgeView.badgeColor = [UIColor redColor];
        badgeView.badgeString  = @"New";
        badgeView.tag = 188;
        UIImageView *imageView = (UIImageView *)[self.view viewWithTag:123];
        [imageView addSubview:badgeView];
//        [aButton addSubview:badgeView];
    }
    
    
}
-(void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    scrollView.contentSize = CGSizeMake(320, 512);
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)createTheBandageView:(NSString *)string
{
     [self.leveyTabBarController.tabBar setBadgeValue:string withButtonIndex:4];
}

#pragma mark - 个人资料
-(IBAction)seeMyProfile:(id)sender
{
    BanBu_PersonDataViewController *myProfile1 = [[BanBu_PersonDataViewController alloc] initWithProfile:[UserDefaults valueForKey:MyAppDataManager.useruid]];
    [self.leveyTabBarController hidesTabBar:YES animated:YES];
    [self.navigationController pushViewController:myProfile1 animated:YES];
    [myProfile1 release];
}

#pragma mark - 我的动态
-(IBAction)seeMyDynamic:(id)sender
{
    [self.leveyTabBarController hidesTabBar:YES animated:YES];
    BanBu_BroadcastTVC *broad = [[BanBu_BroadcastTVC alloc] init];
    broad.useridBroad = MyAppDataManager.useruid;
    broad.title = NSLocalizedString(@"myDynamic", nil);
    [self.navigationController pushViewController:broad animated:YES];
    [broad release];
}

#pragma mark - 我的相册
-(IBAction)seeMyAlbum:(id)sender
{
    BanBu_PersonAlbumDetailController * personAlbum = [[BanBu_PersonAlbumDetailController alloc]initWithStyle:UITableViewStylePlain];
    personAlbum.albumType = album_Type;
    personAlbum.user_id = MyAppDataManager.useruid;
    [self.leveyTabBarController hidesTabBar:YES animated:YES];
    [self.navigationController pushViewController:personAlbum animated:YES];
    [personAlbum release];
    personAlbum = nil;
}
-(IBAction)seeMyAccountInfo:(id)sender
{
    BanBu_MyAccountViewController *account = [[BanBu_MyAccountViewController alloc] init];
    [self.leveyTabBarController hidesTabBar:YES animated:YES];
    [self.navigationController pushViewController:account animated:YES];
    [account release];
}

#pragma mark - seeEmoShop:跳转到表情商店
/**
 * @函数名称：seeEmoShop:
 * @函数描述：点击表情商店的按钮，跳转到表情商店
 * @输入参数：(id)sender:点击的按钮
 * @输出参数：跳转到表情商店
 * @返回值：nil
 * @author：yinlinlin
 */
- (IBAction)seeEmoShop:(id)sender
{
    BanBu_EmoStoreViewController * emoController = [[BanBu_EmoStoreViewController alloc]init];
    [self.leveyTabBarController hidesTabBar:YES animated:YES];
    [self.navigationController pushViewController:emoController animated:YES];
    [emoController release];
}
#pragma mark - seeMySetting::跳转到系统设置
/**
 * @函数名称：seeMySetting:
 * @函数描述：点击按钮，跳转到系统设置
 * @输入参数：(id)sender:点击的按钮
 * @输出参数：跳转到系统设置
 * @返回值：nil
 * @author：***
 */
-(IBAction)seeMySetting:(id)sender
{
    BanBu_SettingViewController *setting = [[BanBu_SettingViewController alloc] init];
    [self.leveyTabBarController hidesTabBar:YES animated:YES];
    [self.navigationController pushViewController:setting animated:YES];
    [setting release];
}

#pragma mark - 关于半圆
-(IBAction)seeAbountKoochat:(id)sender
{
    BanBu_HelpViewController *help=[[BanBu_HelpViewController alloc]init];
    [self.leveyTabBarController hidesTabBar:YES animated:YES];
    [self.navigationController pushViewController:help animated:YES];
    [help release];
}
@end
